package com.example.library.controller;

import com.example.library.bean.model.Book;
import com.example.library.bean.model.User;
import com.example.library.bean.response.Response;
import com.example.library.service.FavoriteOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/favorite")
public class FavoriteAPI {

    @Autowired
    private FavoriteOrderService favoriteOrderService;

    @GetMapping("/get")
    public Response getFavorite(long userId) {
        return favoriteOrderService.getFavoriteBooks(userId);
    }

    @PostMapping("/add")
    public Response addFavorite(long userId, long bookId) {
        User user = new User();
        user.setUserId(userId);
        Book book = new Book();
        book.setBookId(bookId);
        return favoriteOrderService.collectFavoriteBook(user,book);
    }

    @PostMapping("/delete")
    public Response deleteFavorite(long userId, long bookId) {
        return favoriteOrderService.unCollectFavoriteBook(userId,bookId);
    }

}
